import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { RecordVO, RecordForm, RecordQuery } from '@/api/signIn/record/types';
import { TaskVO } from '../task/types';

/**
 * 查询签到记录列表
 * @param query
 * @returns {*}
 */

export const listRecord = (query?: RecordQuery): AxiosPromise<RecordVO[]> => {
  return request({
    url: '/signIn/record/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询签到记录详细
 * @param id
 */
export const getRecord = (id: string | number): AxiosPromise<RecordVO> => {
  return request({
    url: '/signIn/record/' + id,
    method: 'get'
  });
};

/**
 * 新增签到记录
 * @param data
 */
export const addRecord = (data: RecordForm) => {
  return request({
    url: '/signIn/record',
    method: 'post',
    data: data
  });
};

/**
 * 修改签到记录
 * @param data
 */
export const updateRecord = (data: RecordForm) => {
  return request({
    url: '/signIn/record',
    method: 'put',
    data: data
  });
};

/**
 * 删除签到记录
 * @param id
 */
export const delRecord = (id: string | number | Array<string | number>) => {
  return request({
    url: '/signIn/record/' + id,
    method: 'delete'
  });
};

/**
 * 查询当前用户签到情况
 * @param userId
 */
export const getUserTaskSignInRecord = (userId: number, taskId: string | number): AxiosPromise<RecordVO[]> => {
  console.log(`getUserTaskSignInRecord, userId: ${userId}, taskId: ${taskId}`);
  return request({
    url: '/signIn/record/getUserTaskSignInRecord',
    method: 'get',
    params: {
      userId: userId,
      taskId: taskId
    }
  });
};
